#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>

using namespace std;

static bool square(int num) {
    int root = static_cast<int>(1e-6 + sqrt(num));
    return root * root == num;
}

static void fuck(const string& s1, const string& s2, int n1) {
    static int ans = 0;

    // letter -> digit
    string st {to_string(n1)};
    map<char, int> m;
    for (int i = 0; i < s1.size(); ++i) 
        m[s1[i]] = st[i] - '0';

    set<char> set_s1 {s1.begin(), s1.end()};
    set<char> set_n1 {st.begin(), st.end()};
    if (set_s1.size() != set_n1.size())
        return;

    int n2 = 0;
    for (char c : s2)
        n2 = n2 * 10 + m[c];
    if (s2.size() == to_string(n2).size() && square(n2)) { // fuck leading zeros
        if (n1 > ans || n2 > ans) {
            ans = max(n1, n2);
            cout << s1 << ' ' << s2 << ' ' << ans << endl;
        }
    }
}

int main() {
    vector<vector<int>> vv {{0}};
    for (int i = 0; i < 10; ++i) {
        vector<int> v;
        for (auto j = static_cast<int>(pow(10, i)); j < static_cast<int>(pow(10, i + 1)); ++j) {
            if (square(j))
                v.push_back(j);
        }
        vv.push_back(v);
    }

    static vector<string> words {
#include "98.txt"
    };
    sort(words.begin(), words.end(), [](const string& a, const string& b){return a.size() == b.size() ? a < b : a.size() > b.size();});
    for (int i = 0; i < words.size(); ++i) {
        string s {words[i]};
        sort(s.begin(), s.end());
        for (int j = i + 1; j < words.size(); ++j) {
            if (words[i].size() != words[j].size())
                break;

            string t {words[j]};
            sort(t.begin(), t.end());
            if (s != t)
                continue;

            auto& v = vv[t.size()];
            for (int k = 0; k < v.size(); ++k)
                fuck(words[i], words[j], v[k]);
        }
    }
}